<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../Vue全家桶_stu/03_依赖包/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        ul {
            overflow: hidden;
        }

        li {
            width: 50px;
            height: 30px;
            border: 1px solid #000;
            float: left;
            text-align: center;
            line-height: 30px;
        }
        .current {
            border-bottom: 1px solid red;
            cursor: pointer;
            background-color: antiquewhite;
        }
    </style>
</head>

<body>
    <div id="root">
        <ul>
            <li v-for="(item,index) in list" :key="index" @mouseover="hover(index)" :class="{current:currentIndex === index}">{{item}}</li>
        </ul>
    </div>
    <script>
        const vm = new Vue({
            el: '#root',
            data() {
                return {
                    list: ['手机', '电脑', '游戏', '直播', '购物'],
                    //保存当前index
                    currentIndex: ''
                }
            },
            methods: {
                hover(index) {
                    this.currentIndex = index
                }
            }
        })
    </script>
</body>

</html>